When using JS to display the date time, the display of the year in Chrome is incorrect (as shown below), but is normal in IE. For example, the current year is 2014, and the number is displayed at 114.
It seems that the Chrome browser and IE
The GetYear () method was born earlier and used OK in the early days, but after 2000 years this method has a lot of problems because in browsers like Firefox and Safari, getyear always returns the difference between the year and 1900 years, like
GetYear ()The intent of using the getyear () function is to obtain the year, taking 2010 as an example, such as:
var nowd = new Date ();
var YF = Nowd.getyear ();
In IE, the year can be obtained correctly: 2010, but under the FF
Why getyear () cannot get the correct year:In some JS code, especially the old JS code, there may be no way to get the correct year phenomenon, first look at a code example:DOCTYPE HTML>HTML>Head>MetaCharSet= "Utf-8">Metaname= "Author"content= "http:
The Date object has two methods of obtaining the Year:getFullYear () and getyear ()Tested var dt = new Date ();Alert (Dt.getyear ()): IE pop-up: Firefox browser popup: 117 (GetYear () returned in Firefox is the year from January 1, 1990, this is an
IE and Firefox under JavaScript getyear years different browser JavaScript getyear year function compatibility issues
Let me give you an example.
Some websites on Firefox will see this hint.
It's 106 years, August 8.
and using IE browser will
Some netizens showed that the current date of some websites is abnormal () on the page. tests showed that IE is normal, but Firefox, chrome, and chromium are not normal.
After reading the script, we found that the getyear () function is used.
GetYear ()The intent of using the getyear () function is to obtain the year, taking 2010 as an example, such as:
var nowd = new Date ();
var YF = Nowd.getyear ();
In IE, the year can be obtained correctly: 2010, but under the FF and
The JavaScript date.getyear () method returns the year of the specified date according to the Universal Time. GetYear is no longer in use and has been replaced with the getFullYear method.
The value returned by GetYear is the current year minus 1900
The JavaScript getyear () function is intended to get the current "year", such as:
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
In IE browser execution for the correct "2008",
Js|jscript returns the year value in the Date object.
Dateobj.getyear ()
The required option Dateobj parameter is a Date object.
Description
This method is outdated and is provided to maintain backward compatibility. Use the getFullYear method
Last week, I was sorting out a calendar script that I wrote previously. FF always had problems with the display of the year, and I was so depressed. For example, the following script prompts "2007" under IE -- No problem! But does FF prompt "107 "?
The getyear () function of JavaScript is intended to obtain the current "year", for example:
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]
Run "2008" in IE, but "108" in Firefox and
FF always shows problems with the year. For example, the following script prompts "2007" in IE ---- No problem! But does FF prompt "107 "?Getyear of FF returns the value of "current year-1900" (it is said that this was always done before), while ie
Last week, I was sorting out a calendar script that I wrote previously. FF always had problems with the display of the year, and I was so depressed. For example, the following script prompts "2007" under IE -- No problem! But does FF prompt "107 "?
In js, the current year is obtained using var dayObj = new Date (); dayObj. getYear () is used to get the year. I have previously mentioned that browser compatibility issues may occur, that is, we can get the expected results in IE, but it won't
In IE, getyear and getfullyear both obtain the year.
Firefox, Safari, and getyear always return the gap between the year in the date object and the year in 1900. That is to say, if the date object represents this year (2009), 109 is returned.
Today, I got a Firefox. When I installed my blog and browsed it, I saw the [home in the blog garden] on the left.
106Days later] is displayed
693855Day (s)] Result Test
CodeThe problem was found on getyear, and both getmonth and getdate are
Returns the year value in a Date object.
Dateobj.getyear ()
The required option Dateobj parameter is a Date object.
Description
This method is outdated and is provided to maintain backward compatibility. Use the getFullYear method instead.
For the 19
Last week in the collation of a previously written calendar script, FF under the annual display is always a problem, make a depressed s. For example, the following script: under IE hint "2007"-No Problem! But under the FF is prompted "107"?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.